home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0055_Perspective.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  1KB  |  35 lines

  1. {
  2. > If I get  inspired, I will add simple perspective transform to these.
  3. > There, got inspired. Made mistakes. Foley et al are not very good at
  4. > tutoring perspective and I'm kinda ready to be done and post this.
  5.  
  6. >   line(round(x1)+200,round(y1)+200,
  7. >        round(x2)+200,round(y2)+200);
  8.  
  9. try this for perspective (perspecitve is easy to calculate but hard to
  10. explain... I worked it out with a pencil and paper using "similar
  11. triangles, and a whole heap of other math I never thought I'd need, it
  12. took me the best part of 30 minutes but when I saw how simple it really
  13. is...)
  14.  
  15.  this code gives an approximation of perspective... it's pretty good
  16.  when K is more than 3 times the size (maximum dimension) of the object
  17.  
  18. K is some constant... (any constant, about 3-10 times the size of the
  19. object is good) (K is actually the displacement of the viewpoint down
  20. the -Z axis. or something like) K=600 would be a good starting point
  21. }
  22.  
  23.    line(round(x1/(K+z1)*K)+200,round(y1/(K/z1)*K)+200,
  24.         round(x2/(K+z2)*K)+200,round(y2/(K/z2)*K)+200);
  25.  
  26. { not computationally efficient but it shows how it works.
  27.   Here's one that gives "real perspective"
  28. }
  29.  
  30.    line(round(x1/sqrt(sqr(K+z1)+sqr(x1)+sqr(y1))*K,
  31.         round(y1/sqrt(sqr(K+y1)+sqr(y1)+sqr(y1))*K,
  32.         round(x2/sqrt(sqr(K+z2)+sqr(x2)+sqr(y2))*K,
  33.         round(y2/sqrt(sqr(K+y2)+sqr(y2)+sqr(y2))*K);
  34.  
  35.